package stack_use;

import java.util.Deque;
import java.util.LinkedList;

class MyQueue {
    Deque<Integer> s1;
    Deque<Integer> s2;
    public MyQueue() {
        s1=new LinkedList<>();
        s2=new LinkedList<>();
    }
    
    public void push(int x) {
        s1.push(x);
    }
    
    public int pop() {
        if(empty()){
            return -1;
        }
        if(s2.isEmpty()){
            while(!s1.isEmpty()){
                s2.push(s1.pop());
            }
            return s2.pop();
        }else{
            return s2.pop();
        }

    }
    
    public int peek() {
        if(empty()){
            return -1;
        }
        if(s2.isEmpty()){
            while(!s1.isEmpty()){
                s2.push(s1.pop());
            }
            return s2.peek();
        }else{
            return s2.peek();
        }
    }
    
    public boolean empty() {
        if(s1.isEmpty()&&s2.isEmpty()){
            return true;
        }
        return false;
    }
}